package cn.itsource.ymcc.service.impl;

import cn.itsource.ymcc.constant.MQ;
import cn.itsource.ymcc.domain.MediaFile;
import cn.itsource.ymcc.service.IMediaProducer;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.client.producer.SendStatus;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Service;
@Slf4j
@Service
public class MediaProducerImpl implements IMediaProducer {
    @Autowired
    private RocketMQTemplate rocketMQTemplate;

    @Override
    public Boolean syncSend(MediaFile mediaFile) {
        //同步发送消息  异步推流
        SendResult sendResult = rocketMQTemplate.syncSend(MQ.TOPIC_VIDEO_PUSH_SRS + ":" + MQ.TAGS_VIDEO_PUSH_SRS,
                MessageBuilder.withPayload(JSON.toJSONString(mediaFile)).build());//将json格式装为字符串格式进行推送

        log.info("正在向RocketMQ推送消息.......................");
        return sendResult.getSendStatus() == SendStatus.SEND_OK;
    }
}
